﻿#region << 文件说明 >>
/*----------------------------------------------------------------
 * 命名空间：Vampirewal.Core.WPF.Theme.FrameworkControl.CustomUC
 * 唯一标识：b146e7a9-2e8d-4232-a4f2-28b41352140e
 * 文件名：MdiChildViewBase
 * 
 * 创建者：杨程
 * 电子邮箱：235160615@qq.com
 * 创建时间：2024/10/8 16:02:33
 * 版本：V1.0.0
 * 描述：
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *
 * 版本：V1.0.1
 *----------------------------------------------------------------*/
#endregion << 文件说明 >>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Vampirewal.Core.WPF.Theme;

/// <summary>
/// 
/// </summary>
public class MdiChildViewBase : UcViewBase, IMdiChildViewBase
{
    /// <summary>   
    /// 构造函数
    /// </summary>
    public MdiChildViewBase()
    {
        var MdiChildViewBaseStyle = base.res["MdiChildViewBase"] as Style;

        this.Style = MdiChildViewBaseStyle;
    }

    static MdiChildViewBase()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(MdiChildViewBase), new FrameworkPropertyMetadata(typeof(MdiChildViewBase)));
    }

    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();

        #region 标题区域
        var titleArea = this.Template.FindName("titleArea", this) as StackPanel;

        TextBlock title = new TextBlock()
        {
            Text = ViewSetting.Title,
            Foreground=Brushes.White,
        };

        titleArea.Children.Add(title); 
        #endregion


    }

    public string IconPath { get; set; }

    private MdiChildViewSetting ViewSetting { get; set; }

    public void Setting(MdiChildViewSetting setting)
    {
        ViewSetting= setting;

        this.SetValue(Window.WidthProperty, setting.WindowWidth);
        this.SetValue(Window.HeightProperty, setting.WindowHeight);

        //UcView.Content = setting.UcView;

        setting.MdiView.Width = double.NaN;
        setting.MdiView.Height = double.NaN;

        this.SetValue(Window.DataContextProperty, setting.MdiView.DataContext);

        ViewModelBase vm = setting.MdiView.DataContext as ViewModelBase;
        ////vm.View = this;
        vm.ViewId = this.ViewId;

        vm.PassData(setting.PassData);

        if (!string.IsNullOrEmpty(setting.IconStr))
        {
            this.IconPath = setting.IconStr;
            //this.IconPath = new BitmapImage(new Uri(setting.IconStr));
            //this.ShowInTaskbar = true;
        }
        else
        {
            //this.ShowInTaskbar = false;
        }

        this.Title = setting.Title;


        if (!string.IsNullOrEmpty(setting.Background))
        {
            this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(setting.Background));
        }
        else
        {
            this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#2F3437"));
        }

        if (!string.IsNullOrEmpty(setting.Foreground))
        {
            this.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(setting.Foreground));
        }
        else
        {
            this.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#EBEBEB"));
        }

        if (!string.IsNullOrEmpty(setting.WindowBorderBrush))
        {
            this.BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(setting.WindowBorderBrush));
        }
        else
        {
            this.BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#3F4447"));
        }

        //this.TitleFontSize = setting.TitleFontSize;

        //if (setting.CloseWindowCommand != null)
        //{
        //    this.CloseWindowCommand = setting.CloseWindowCommand;
        //    this.CloseWindowCommandParameter = setting.CloseWindowCommandParameter;
        //}
    }
}